<template>
  <div class="contact-page">
    <!-- 顶部导航栏 -->
    <Header />
    
    <div class="main-content">
      <div class="container">
        <!-- 页面标题 -->
        <div class="page-header">
          <h1>{{ $t('nav.contact') }}</h1>
          <p>我们随时为您提供帮助</p>
        </div>
        
        <div class="contact-content">
          <!-- 联系信息 -->
          <div class="contact-info-section">
            <h2>联系信息</h2>
            <div class="info-grid">
              <div class="info-item">
                <EnvironmentOutlined class="info-icon" />
                <div class="info-content">
                  <h3>公司地址</h3>
                  <p>北京市朝阳区xxx街道xxx号</p>
                </div>
              </div>
              <div class="info-item">
                <PhoneOutlined class="info-icon" />
                <div class="info-content">
                  <h3>客服热线</h3>
                  <p>400-123-4567</p>
                </div>
              </div>
              <div class="info-item">
                <MailOutlined class="info-icon" />
                <div class="info-content">
                  <h3>邮箱地址</h3>
                  <p>service@webmall.com</p>
                </div>
              </div>
              <div class="info-item">
                <ClockCircleOutlined class="info-icon" />
                <div class="info-content">
                  <h3>工作时间</h3>
                  <p>周一至周日 9:00-18:00</p>
                </div>
              </div>
            </div>
          </div>
          
          <!-- 联系表单 -->
          <div class="contact-form-section">
            <h2>发送消息</h2>
            <a-form
              :model="formData"
              :rules="rules"
              @finish="handleSubmit"
              layout="vertical"
              class="contact-form"
            >
              <a-form-item label="姓名" name="name">
                <a-input
                  v-model:value="formData.name"
                  placeholder="请输入您的姓名"
                  size="large"
                />
              </a-form-item>
              
              <a-form-item label="{{ $t('user.email') }}" name="email">
                <a-input
                  v-model:value="formData.email"
                  placeholder="请输入您的邮箱"
                  size="large"
                />
              </a-form-item>
              
              <a-form-item label="主题" name="subject">
                <a-select
                  v-model:value="formData.subject"
                  placeholder="请选择咨询主题"
                  size="large"
                >
                  <a-select-option value="general">一般咨询</a-select-option>
                  <a-select-option value="order">订单问题</a-select-option>
                  <a-select-option value="product">商品咨询</a-select-option>
                  <a-select-option value="payment">支付问题</a-select-option>
                  <a-select-option value="refund">退款申请</a-select-option>
                  <a-select-option value="other">其他问题</a-select-option>
                </a-select>
              </a-form-item>
              
              <a-form-item label="消息内容" name="message">
                <a-textarea
                  v-model:value="formData.message"
                  placeholder="请详细描述您的问题或建议"
                  :rows="6"
                  size="large"
                />
              </a-form-item>
              
              <a-form-item>
                <a-button
                  type="primary"
                  html-type="submit"
                  size="large"
                  :loading="loading"
                  block
                >
                  发送消息
                </a-button>
              </a-form-item>
            </a-form>
          </div>
        </div>
        
        <!-- 常见问题 -->
        <div class="faq-section">
          <h2>常见问题</h2>
          <a-collapse v-model:activeKey="activeKeys" accordion>
            <a-collapse-panel key="1" header="如何注册账户？">
              <p>点击网站右上角的"{{ $t('nav.register') }}"按钮，填写相关信息即可完成注册。</p>
            </a-collapse-panel>
            <a-collapse-panel key="2" header="忘记密码怎么办？">
              <p>在登录页面点击"{{ $t('user.forgotPassword') }}"，通过邮箱验证即可重置密码。</p>
            </a-collapse-panel>
            <a-collapse-panel key="3" header="如何修改收货地址？">
              <p>登录后在个人中心可以添加、修改和删除收货地址。</p>
            </a-collapse-panel>
            <a-collapse-panel key="4" header="支持哪些支付方式？">
              <p>我们支持支付宝、微信支付、银行卡等多种支付方式。</p>
            </a-collapse-panel>
            <a-collapse-panel key="5" header="如何申请退款？">
              <p>在订单详情页面点击"申请退款"，填写退款原因即可。</p>
            </a-collapse-panel>
          </a-collapse>
        </div>
      </div>
    </div>
    
    <!-- 底部信息 -->
    <Footer />
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { message } from 'ant-design-vue'
import {
  EnvironmentOutlined,
  PhoneOutlined,
  MailOutlined,
  ClockCircleOutlined
} from '@ant-design/icons-vue'
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'

// 响应式数据
const loading = ref(false)
const activeKeys = ref(['1'])

const formData = reactive({
  name: '',
  email: '',
  subject: '',
  message: ''
})

// 表单验证规则
const rules = {
  name: [
    { required: true, message: '请输入您的姓名', trigger: 'blur' },
    { min: 2, max: 20, message: '姓名长度在2-20个字符之间', trigger: 'blur' }
  ],
  email: [
    { required: true, message: '请输入您的邮箱', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
  ],
  subject: [
    { required: true, message: '请选择咨询主题', trigger: 'change' }
  ],
  message: [
    { required: true, message: '请输入消息内容', trigger: 'blur' },
    { min: 10, max: 500, message: '消息内容长度在10-500个字符之间', trigger: 'blur' }
  ]
}

// 方法
const handleSubmit = async (values) => {
  loading.value = true
  
  try {
    // 这里应该调用实际的API发送消息
    // await api.sendContactMessage(values)
    
    // 模拟API调用
    await new Promise(resolve => setTimeout(resolve, 1000))
    
    message.success('消息发送成功，我们会尽快回复您')
    
    // 重置表单
    Object.assign(formData, {
      name: '',
      email: '',
      subject: '',
      message: ''
    })
  } catch (error) {
    console.error('发送消息失败:', error)
    message.error('发送失败，请重试')
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.contact-page {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.main-content {
  flex: 1;
  padding: 20px 0;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
}

.page-header h1 {
  font-size: 32px;
  font-weight: bold;
  color: #333;
  margin: 0 0 10px 0;
}

.page-header p {
  color: #666;
  font-size: 16px;
  margin: 0;
}

.contact-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-bottom: 40px;
}

.contact-info-section,
.contact-form-section {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 30px;
}

.contact-info-section h2,
.contact-form-section h2 {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0 0 30px 0;
}

.info-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.info-item {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.info-icon {
  font-size: 24px;
  color: #1890ff;
  flex-shrink: 0;
  margin-top: 2px;
}

.info-content h3 {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0 0 5px 0;
}

.info-content p {
  font-size: 14px;
  color: #666;
  margin: 0;
}

.contact-form {
  max-width: 100%;
}

.faq-section {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 30px;
}

.faq-section h2 {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0 0 20px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-content {
    padding: 15px 0;
  }
  
  .page-header h1 {
    font-size: 24px;
  }
  
  .contact-content {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .contact-info-section,
  .contact-form-section,
  .faq-section {
    padding: 20px;
  }
  
  .info-item {
    padding: 15px;
  }
}
</style> 